package com.lanou.controller;

import com.lanou.entity.InfoNotice;
import com.lanou.service.InfoNoticeService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName InfoNoticeController
 * @Description TODO
 * @Author chenzhaobao
 * @Date 2025年08月14日 11:11
 * @Version 1.0
 */
@RestController
@RequestMapping("/infoNotice")
public class InfoNoticeController {
    @Autowired
    private InfoNoticeService infoNoticeService;
    @PostMapping
    public R insert(@RequestBody InfoNotice infoNotice){
        int i = infoNoticeService.insert(infoNotice);
        if (i > 0) {
            return R.ok("添加成功");
        } else {
            return R.error("添加失败");
        }
    }
    @DeleteMapping("/{id}")
    public R deleteById( @PathVariable Integer id){
        int i = infoNoticeService.deleteById(id);
        if (i > 0) {
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
    @PutMapping
    public R updateById(@RequestBody InfoNotice infoNotice){
        int i = infoNoticeService.updateById(infoNotice);
        if (i > 0) {
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }

    }
    @GetMapping("/{id}")
    public R selectById( @PathVariable Integer id){
        InfoNotice infoNotice = infoNoticeService.selectById(id);
        if (infoNotice != null) {
            return R.ok(infoNotice);
        }else {
            return R.error("查询失败");
        }
    }
    @GetMapping
    public R selectAll(){
        List<InfoNotice> infoNoticeList = infoNoticeService.selectAll();
        if (infoNoticeList != null && infoNoticeList.size() > 0) {
            return R.ok(infoNoticeList);
        }else {
            return R.error("查询失败");
        }
    }
}
